This notebook reproduces graphs from:
http://johncarlosbaez.wordpress.com/2014/05/29/warming-slowdown-2/
In [1]:
%pylab inline
import urllib2
import os
from IPython.display import Image
import numpy.ma as ma
from scipy.interpolate import UnivariateSpline
In [2]:
url = "http://www.esrl.noaa.gov/psd/gcos_wgsp/Timeseries/Data/GLBTSSST.long.data"
filename = os.path.join("data", os.path.basename(url))
open(filename, "w").write(urllib2.urlopen(url).read())
Load the data (the last year will typically have missing values for the last few months):
In [3]:
D = genfromtxt(filename, skip_header=1, skip_footer=17, missing_values={None: "-999"}, usemask=True, dtype=int)
D
Out[3]:
We average monthly temperature for each year (we have to divide by 100 to get the temperature is in C
):
In [4]:
years = D[:, 0]
T = array(ma.average(D[:, 1:]/100., axis=1)) # Make sure 'average' ignores missing values
Calculate average temperature between the years 1950-1980 (including both ends):
In [5]:
Tavg = average(T[1950-years[0]:1980-years[0]+1])
Tavg
Out[5]:
Calculate temperature anomaly
In [6]:
Tanom = T - Tavg
Plot the data (first plot), compare to the original plot (second plot):
In [7]:
# Get the years and temperatures after 1950:
x = years[1950-years[0]:]
y = Tanom[1950-years[0]:]
figure(figsize=(10, 5))
bar(x, y, 0.4, lw=0)
xlim([1948, 2015])
xlabel("Year")
ylabel("Temperatuer anomaly in Degrees Celsius")
title("Mean Temperature Anomalies Relative to 1950-1980 baseline")
show()
Image(filename="data/UAH_LT_1979_thru_June_2013_v5.6.png")
show()
Image(url="http://math.ucr.edu/home/baez/ecological/galkowski/AnnualAnomaliesBarChart.png", width=620)
Out[7]:
Let's calculate "two trendlines obtained by applying a smoothing spline, one smoothing more than another". It is not clear what spline parameters to use, so we chose cubic splines and smoothing parameters s=1
and s=0.4
, that seem to reproduce the original graph at least qualitatively.
In [8]:
s = UnivariateSpline(x, y, k=3, s=1)
y_spline_1 = s(x)
s = UnivariateSpline(x, y, k=3, s=0.4)
y_spline_2 = s(x)
Plot the data (first plot), compare to the original plot (second plot):
In [9]:
figure(figsize=(10, 5))
bar(x, y, 0.4, lw=0)
plot(x, y_spline_1, "m-", lw=2)
plot(x, y_spline_2, "m--", lw=2)
xlim([1948, 2015])
xlabel("Year")
ylabel("Temperatuer anomaly in Degrees Celsius")
title("Mean Temperature Anomalies Relative to 1950-1980 baseline")
show()
Image(url="http://math.ucr.edu/home/baez/ecological/galkowski/TemplateForSyntheticModel_a.png", width=620)
Out[9]: